package o;

import android.os.Process;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy.Builder;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.ActivityChooserView.ActivityChooserViewAdapter;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public final class uv implements ExecutorService {
    private static final long ˎ = TimeUnit.SECONDS.toMillis(10);
    private static volatile int ॱ;
    private final ExecutorService ˋ;

    static final class b implements ThreadFactory {
        final c ˊ;
        final boolean ˋ;
        private final String ˏ;
        private int ॱ;

        b(String str, c cVar, boolean z) {
            this.ˏ = str;
            this.ˊ = cVar;
            this.ˋ = z;
        }

        public synchronized Thread newThread(@NonNull Runnable runnable) {
            Thread anonymousClass3;
            anonymousClass3 = new Thread(this, runnable, "glide-" + this.ˏ + "-thread-" + this.ॱ) {
                final /* synthetic */ b ˋ;

                public void run() {
                    Process.setThreadPriority(9);
                    if (this.ˋ.ˋ) {
                        StrictMode.setThreadPolicy(new Builder().detectNetwork().penaltyDeath().build());
                    }
                    try {
                        super.run();
                    } catch (Throwable th) {
                        this.ˋ.ˊ.ॱ(th);
                    }
                }
            };
            this.ॱ++;
            return anonymousClass3;
        }
    }

    public interface c {
        public static final c ˊ = new c() {
            public void ॱ(Throwable th) {
                if (th != null && Log.isLoggable("GlideExecutor", 6)) {
                    Log.e("GlideExecutor", "Request threw uncaught throwable", th);
                }
            }
        };
        public static final c ˋ = ˊ;
        public static final c ˎ = new c() {
            public void ॱ(Throwable th) {
                if (th != null) {
                    throw new RuntimeException("Request threw uncaught throwable", th);
                }
            }
        };
        public static final c ˏ = new c() {
            public void ॱ(Throwable th) {
            }
        };

        void ॱ(Throwable th);
    }

    public static uv ॱ() {
        return ˊ(1, "disk-cache", c.ˋ);
    }

    public static uv ˊ(int i, String str, c cVar) {
        return new uv(new ThreadPoolExecutor(i, i, 0, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new b(str, cVar, true)));
    }

    public static uv ˏ() {
        return ˎ(ˊ(), "source", c.ˋ);
    }

    public static uv ˎ(int i, String str, c cVar) {
        return new uv(new ThreadPoolExecutor(i, i, 0, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new b(str, cVar, false)));
    }

    public static uv ˎ() {
        return new uv(new ThreadPoolExecutor(0, ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED, ˎ, TimeUnit.MILLISECONDS, new SynchronousQueue(), new b("source-unlimited", c.ˋ, false)));
    }

    public static uv ˋ() {
        return ˎ(ˊ() >= 4 ? 2 : 1, c.ˋ);
    }

    public static uv ˎ(int i, c cVar) {
        return new uv(new ThreadPoolExecutor(i, i, 0, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new b("animation", cVar, true)));
    }

    @VisibleForTesting
    uv(ExecutorService executorService) {
        this.ˋ = executorService;
    }

    public void execute(@NonNull Runnable runnable) {
        this.ˋ.execute(runnable);
    }

    @NonNull
    public Future<?> submit(@NonNull Runnable runnable) {
        return this.ˋ.submit(runnable);
    }

    @NonNull
    public <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> collection) throws InterruptedException {
        return this.ˋ.invokeAll(collection);
    }

    @NonNull
    public <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> collection, long j, @NonNull TimeUnit timeUnit) throws InterruptedException {
        return this.ˋ.invokeAll(collection, j, timeUnit);
    }

    @NonNull
    public <T> T invokeAny(@NonNull Collection<? extends Callable<T>> collection) throws InterruptedException, ExecutionException {
        return this.ˋ.invokeAny(collection);
    }

    public <T> T invokeAny(@NonNull Collection<? extends Callable<T>> collection, long j, @NonNull TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
        return this.ˋ.invokeAny(collection, j, timeUnit);
    }

    @NonNull
    public <T> Future<T> submit(@NonNull Runnable runnable, T t) {
        return this.ˋ.submit(runnable, t);
    }

    public <T> Future<T> submit(@NonNull Callable<T> callable) {
        return this.ˋ.submit(callable);
    }

    public void shutdown() {
        this.ˋ.shutdown();
    }

    @NonNull
    public List<Runnable> shutdownNow() {
        return this.ˋ.shutdownNow();
    }

    public boolean isShutdown() {
        return this.ˋ.isShutdown();
    }

    public boolean isTerminated() {
        return this.ˋ.isTerminated();
    }

    public boolean awaitTermination(long j, @NonNull TimeUnit timeUnit) throws InterruptedException {
        return this.ˋ.awaitTermination(j, timeUnit);
    }

    public String toString() {
        return this.ˋ.toString();
    }

    public static int ˊ() {
        if (ॱ == 0) {
            ॱ = Math.min(4, vc.ॱ());
        }
        return ॱ;
    }
}
